package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.CusDept;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.system.service.ICusDeptService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CusProduce;
import com.ruoyi.system.service.ICusProduceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户产品Controller
 * 
 * @author ruoyi
 * @date 2024-03-21
 */
@RestController
@RequestMapping("/system/produce")
public class CusProduceController extends BaseController
{
    @Autowired
    private ICusProduceService cusProduceService;

    @Autowired
    private ICusDeptService cusDeptService;

    /**
     * 查询用户产品列表
     */
    @PreAuthorize("@ss.hasPermi('system:produce:list')")
    @GetMapping("/list")
    public TableDataInfo list(CusProduce cusProduce)
    {
        startPage();
        List<CusProduce> list = cusProduceService.selectCusProduceList(cusProduce);
        return getDataTable(list);
    }

    /**
     * 导出用户产品列表
     */
    @PreAuthorize("@ss.hasPermi('system:produce:export')")
    @Log(title = "用户产品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CusProduce cusProduce)
    {
        List<CusProduce> list = cusProduceService.selectCusProduceList(cusProduce);
        ExcelUtil<CusProduce> util = new ExcelUtil<CusProduce>(CusProduce.class);
        util.exportExcel(response, list, "用户产品数据");
    }

    /**
     * 获取用户产品详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:produce:query')")
    @GetMapping(value = "/{productId}")
    public AjaxResult getInfo(@PathVariable("productId") Long productId)
    {
        return success(cusProduceService.selectCusProduceByProductId(productId));
    }

    /**
     * 新增用户产品
     */
    @PreAuthorize("@ss.hasPermi('system:produce:add')")
    @Log(title = "用户产品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CusProduce cusProduce)
    {
        return toAjax(cusProduceService.insertCusProduce(cusProduce));
    }

    /**
     * 修改用户产品
     */
    @PreAuthorize("@ss.hasPermi('system:produce:edit')")
    @Log(title = "用户产品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CusProduce cusProduce)
    {
        return toAjax(cusProduceService.updateCusProduce(cusProduce));
    }

    /**
     * 删除用户产品
     */
    @PreAuthorize("@ss.hasPermi('system:produce:remove')")
    @Log(title = "用户产品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{productIds}")
    public AjaxResult remove(@PathVariable Long[] productIds)
    {
        return toAjax(cusProduceService.deleteCusProduceByProductIds(productIds));
    }

    /**
     * 获取部门树列表
     */
    @PreAuthorize("@ss.hasPermi('system:user:list')")
    @GetMapping("/deptTree")
    public AjaxResult deptTree(CusDept dept)
    {
        return success(cusDeptService.selectDeptTreeList(dept));
    }
}
